package com.soundai.skill.helloworld.Service;

import com.soundai.skill.helloworld.HttpHelper.HttpClientHelper;
import com.soundai.skill.helloworld.config.uriConfig;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.omg.CORBA.PUBLIC_MEMBER;

/**
 *
 * TODO:AI智能服务
 *
 */
public class AIService {

    /**
     * 获取AI识别反馈
     * @param  key
     * * @param  value
     * @return
     */
    public static String getAiInfo(String key,String value){
        //String key = jsonObject.get("area").toString();
        //String value =jsonObject.get("action").toString();
        String doGetUrl = String.format(uriConfig.areaActionUrl,key,value,"");
        String returnAreaAction = HttpClientHelper.doGet(doGetUrl);
        JSONArray arr = JSONArray.fromObject(returnAreaAction);

        String pid = "";
        for (int i = 0; i <arr.size() ; i++) {
            JSONObject objSoundInfo = arr.getJSONObject(i);
            if(pid.equals(""))
                pid = objSoundInfo.get("id").toString();
            else
                pid = ","+objSoundInfo.get("id").toString();
        }
        //获取AI对话信息，映射对应处置操作
        String comfirmValue = getConfirmInfo(pid);
        //JSONObject returnJson = new JSONObject();
        return  comfirmValue;
    }

    /**
     * 获取AI对话信息，映射对应处置操作
     * @param pid
     * @return
     */
    public static String getConfirmInfo(String pid){
        String returnConfirmInfo = HttpClientHelper.doGet(String.format(uriConfig.confirmInfoUrl,pid));
        JSONArray arr = JSONArray.fromObject(returnConfirmInfo);
        String value = "";
        for (int i = 0; i <arr.size() ; i++) {
            JSONObject objSoundInfo = arr.getJSONObject(i);
            value = objSoundInfo.get("v").toString();
        }
        return value;
    }


}
